package com.sinven.daoImpl;

import com.sinven.dao.GoodsDao;
import com.sinven.entity.GoodsAllInfo;
import com.sinven.entity.GoodsSimpleInfo;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository("GoodsDaoImpl")
public class GoodsDaoImpl implements GoodsDao{

//    @Autowired
//    @Qualifier("hibernateTemplate")
//    private HibernateTemplate hibernateTemplate;

    @Resource
    private SessionFactory sessionFactory;

    protected Session getSession(){
         return sessionFactory.getCurrentSession();
    }

    /**
     * 获取简单商品信息
     * @param hql
     * @return list
     */
    @Override
    public List<GoodsSimpleInfo> findGoodsInfo(String hql) {
        Session currentSession = this.getSession();
        Query query = currentSession.createQuery(hql);
        return query.list();
    }


    /**
     *
     * @param hql
     * @return
     */
    @Override
    public List<GoodsAllInfo> findGoodsAllInfo(String hql) {
        Session currentSession = sessionFactory.getCurrentSession();
        Query query = currentSession.createQuery(hql);
        return query.list();
    }
}
